﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using Billing.Models;
using Billing.IService.Entry;
using Common.IService.Entry;

namespace Billing.Controllers
{
    public class PayController : AsyncControllerBase
    {
        #region Get

        public void GetAsync(string orderCode, string sourceCode)
        {
            GetPayModel model = new GetPayModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:pay:end"
            };
            InitModel(model);
        }

        public ActionResult GetCompleted(OrderEntry entry)
        {
            return entry == null ? null : Json(entry);
        }

        #endregion Get

        #region New

        public void NewAsync(string orderCode, string sourceCode, decimal? amount, string owner)
        {
            NewPayModel model = new NewPayModel
            {
                OrderCode = orderCode,
                OrderOwner = owner,
                OrderSource = sourceCode,
                OrderAmount = amount == null ? decimal.Zero : amount.Value,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:pay:end"
            };
            InitModel(model);
        }

        public ActionResult NewCompleted(OrderEntry entry)
        {
            return entry == null ? null : Json(entry);
        }

        #endregion New

        #region End

        public void EndAsync(string orderCode, string sourceCode, decimal? amount)
        {
            EndPayModel model = new EndPayModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Amount =amount==null?decimal.Zero:amount.Value,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:pay:end"
            };
            InitModel(model);
        }

        public ActionResult EndCompleted(byte result)
        {
            return Content(result.ToString());
        }

        #endregion End

        #region Query

        public void QueryPageAsync(string user, string resource, string begin, string end, int page, int size)
        {
            QueryPagePayModel model = new QueryPagePayModel
            {
                OrderSourceCode = resource,
                OrderUser = user,
                BeginTime = begin,
                EndTime = end,
                PageIndex = page,
                PageSize = size,
                Source = Request.UserHostAddress,
                ConfigName = "filter:ip:pay:end"
            };
            InitModel(model);
        }

        public ActionResult QueryPageCompleted(int count, OrderEntry[] data)
        {
            return Json(new QueryPageEntry<OrderEntry> { Count = count, Data = data });
        }

        #endregion Query

        #region Validate

        public void ValidateAsync(string orderCode, string sourceCode, decimal? amount, string owner, byte status)
        {
            ValidatePayModel model = new ValidatePayModel
            {
                OrderCode = orderCode,
                OrderSource = sourceCode,
                Onwer = owner,
                Amount = amount == null ? decimal.Zero : amount.Value,
                Status = status,
                Source = Request.UserHostAddress
            };
            InitModel(model);
        }

        public ActionResult ValidateCompleted(bool result)
        {
            return Content(result.ToString());
        }

        #endregion Validate

    }
}
